/**
 * 
 */
package com.cnhaimei.vod.logic;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.cnhaimei.base.TransparentActivity;
import com.cnhaimei.vod.R;
import com.cnhaimei.vod.net.XVod;
import com.cnhaimei.vod.net.dc.Player;
import com.cnhaimei.vod.util.Const;

/**
 * 气氛
 * 
 * @author Jin001.Wu@gmail.com <br>
 * @date 2011-7-4
 * 
 */
public class MoodActivity extends TransparentActivity {
	int mImageViewHeight = 150;
	int mImageViewWidth = 150;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.v8_mood);
		initView();
	}

	private void initView() {
		setClickable(R.id.whoop, R.id.catcall, R.id.give, R.id.kick_up, R.id.close);
		
		updatePosition();
	}


	//调整中间6个板块的位置
	private void updatePosition()
	{
		DisplayMetrics dMetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
		float xdpi = dMetrics.widthPixels;//dMetrics.xdpi;
		float ydpi = dMetrics.heightPixels;//dMetrics.ydpi;
		float fScaleX = xdpi / 480;//xdpi / 240;
		float fScaleY = ydpi / 800;//ydpi / 240;

		float fTopBottomScale = xdpi / 540;
		int nHeadHeight = (int)(98 * fTopBottomScale);//(int) (98 * fScaleY);
		int nFootHeight = (int)(116 * fTopBottomScale);//(int) (116 * fScaleY);		
		int nPanelHeight = dMetrics.heightPixels - nHeadHeight - nFootHeight;
		View layout = findViewById(R.id.float_layout);
		ViewGroup.LayoutParams lp = layout.getLayoutParams();
		if (lp == null) {
			lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, nPanelHeight);
		}
		lp.height = nPanelHeight;
		layout.setLayoutParams(lp);
		
		int nPaddingX = (int)((dMetrics.widthPixels - (mImageViewWidth + 5)*fScaleX*2)/4);
		updateImageViewPos(fScaleX, fScaleY, nPaddingX, R.id.whoop, R.id.catcall, R.id.give, R.id.kick_up);		
	}

	protected void updateImageViewPos(float fScaleX, float fScaleY, int paddingX, int... ids) {
		for (int i = 0; i < ids.length; i++) {
			View v = findViewById(ids[i]);
			if (v != null)
			{
				ViewGroup.LayoutParams lp = v.getLayoutParams();
				lp.width = (int) ((int)mImageViewWidth * fScaleX + paddingX*2);
				lp.height = lp.width;
				v.setLayoutParams(lp);
				((ImageView)v).setScaleType(ScaleType.FIT_XY);
				v.setPadding(paddingX, 0, paddingX, 0);
			}
		}
	}
	
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.whoop:
			setPalyerMood( Const.Mood.WHOOP);
			break;
		case R.id.catcall:
			setPalyerMood(Const.Mood.CUTCALL);
			break;
		case R.id.give:
			setPalyerMood(Const.Mood.GIVE);
			break;
		case R.id.kick_up:
			setPalyerMood(Const.Mood.KICKUP);
			break;
		case R.id.close:
			finish();
			break;
		default:
			super.onClick(v); // need parent
			break;
		}
	}
	
	private void setPalyerMood(int type) {
		XVod.G().setPlayerSet(Player.PLAYER_SET_MOOD, type);
//		finish();
	}

}
